home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE09 / TWAVE / IMAGESND.PAS < prev    next >
Pascal/Delphi Source File  |  1996-03-28  |  1KB  |  66 lines

  1. unit Imagesnd;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, WavePlay, MMSystem;
  8.  
  9. type
  10.   TImageSnd = class(TImage)
  11.   private
  12.     { Private declarations }
  13.     FSndTrack: TWave;
  14.     procedure SetSndTrack(NewTrack: TWave);
  15.   protected
  16.     { Protected declarations }
  17.     procedure Play(Sender: TObject);
  18.   public
  19.     { Public declarations }
  20.     constructor Create(AOwner: TComponent); override;
  21.     destructor Destroy; override;
  22.   published
  23.     { Published declarations }
  24.     property SndTrack: TWave read FSndTrack write SetSndTrack;
  25.   end;
  26.  
  27. procedure Register;
  28.  
  29. implementation
  30.  
  31. { construct TImageSnd }
  32. constructor TImageSnd.Create(AOwner: TComponent);
  33. begin
  34.   inherited Create(AOwner);
  35.   { create class instance }
  36.   FSndTrack := TWave.Create;
  37.   inherited OnClick := Play;
  38. end;
  39.  
  40. destructor TImageSnd.Destroy;
  41. begin
  42.   { must make this call or crash and burn }
  43.   sndPlaySound(nil, 0);
  44.   { free class instance }
  45.   FSndTrack.Free;
  46.   inherited Destroy;
  47. end;
  48.  
  49. { method to play WaveAudio data }
  50. procedure TImageSnd.Play(Sender: TObject);
  51. begin
  52.   sndPlaySound(FSndTrack.WaveData.Memory, snd_ASync or snd_Memory);
  53. end;
  54.  
  55. procedure TImageSnd.SetSndTrack(NewTrack: TWave);
  56. begin
  57.   FSndTrack.Assign(NewTrack);
  58. end;
  59.  
  60. procedure Register;
  61. begin
  62.   RegisterComponents('Misc', [TImageSnd]);
  63. end;
  64.  
  65. end.
  66.